home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DUProjects / Calc / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  4.4 KB  |  150 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 1 $
  2. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef FRAME_H
  6. #include "Frame.h"
  7. #endif
  8.  
  9. #ifndef PART_H
  10. #include "Part.h"
  11. #endif
  12.  
  13. #ifndef DEFINES_K
  14. #include "Defines.k"            // #defines
  15. #endif
  16.  
  17. // ----- Framework Layer -----
  18. #ifndef FWUTIL_H
  19. #include "FWUtil.h"                // FW_CFacetContext, FW_Beep()
  20. #endif
  21.  
  22. #ifndef FWCONTXT_H
  23. #include "FWContxt.h"            // FW_CViewContext
  24. #endif
  25.  
  26. #include "FWTabber.h"            // FW_CViewTabber
  27. #include "FWIdle.h"                // FW_CIdler
  28.  
  29. #ifndef FWBUTTON_H
  30. #include "FWButton.h"
  31. #endif
  32.  
  33. #ifndef FWEDVIEW_H
  34. #include "FWEdView.h"
  35. #endif
  36.  
  37. // OS Layer ------------------------- 
  38. #ifndef SLMIXCOS_H
  39. #include "SLMixOS.h"            // FW_Beep
  40. #endif
  41.  
  42. // ----- Graphic Includes -----
  43. #ifndef FWRECT_H
  44. #include <FWRect.h>                // FW_CRect
  45. #endif
  46.  
  47. #ifndef FWRECSHP_H
  48. #include "FWRecShp.h"            // FW_CRectShape
  49. #endif
  50.  
  51. //========================================================================================
  52. #ifdef FW_BUILD_MAC
  53. #pragma segment Calc
  54. #endif
  55.  
  56. //========================================================================================
  57. FW_DEFINE_AUTO(CCalcFrame)
  58.  
  59. //========================================================================================
  60. CCalcFrame::CCalcFrame(Environment* ev, ODFrame* odFrame, 
  61.                                     FW_CPresentation* presentation, CCalcPart* calcPart)
  62.   : FW_CFrame(ev, odFrame, presentation, calcPart),
  63.       fCalcPart(calcPart),
  64.       fIdler(NULL),
  65.       fViewTabber(NULL)
  66. {
  67.     fIdler = FW_NEW(FW_CIdler, (this, 15));    // to blink text insertion point
  68.     fIdler->RegisterIdle(ev);                
  69.     FW_END_CONSTRUCTOR
  70. }
  71.  
  72. //----------------------------------------------------------------------------------------
  73. CCalcFrame::~CCalcFrame()
  74. {
  75.     FW_START_DESTRUCTOR
  76.     delete fIdler;
  77.     // fViewTabber deleted for us
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. void 
  82. CCalcFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  83. {
  84.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  85.     // draw background picture from part editor shared library
  86.     FW_CSharedLibraryResourceFile resFile(ev);
  87.     const short kODFPictID = 2000;
  88.     const short kCalcPictID = 2001;
  89.     const FW_Fixed kWidth = FW_IntToFixed(280);
  90.     const FW_Fixed kHeight = FW_IntToFixed(200);
  91.      FW_CPictureShape::RenderPicture(context,
  92.                                     FW_CPicture(resFile, kCalcPictID),
  93.                                     FW_CRect(FW_IntToFixed(0), FW_IntToFixed(0), 
  94.                                                 kWidth, kHeight));
  95.  
  96. }
  97.  
  98. //----------------------------------------------------------------------------------------
  99. void 
  100. CCalcFrame::CreateSubViews(Environment* ev)
  101. {        
  102.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  103.     //             Use the macro FW_DO_NOT_DEAD_STRIP for those classes which are not 
  104.     //             referenced anywhere else in your part's code.
  105.     FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
  106.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  107.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  108.     
  109.     this->CreateSubViewsFromResource(ev, kCalcView);
  110.     FW_CButton* calcButton = (FW_CButton*)FindViewById(ev, kCalculateButtonID);
  111.     calcButton->LinkControlTo(ev, this);
  112.     fViewTabber = new FW_CViewTabber(ev, this); 
  113. }
  114.  
  115.  
  116. //----------------------------------------------------------------------------------------
  117. void 
  118. CCalcFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
  119. {
  120.     if (notification.GetMessage() == FW_kButtonPressedMsg)  {
  121.         fCalcPart->MySetLoanAmount( MyGetEditValue(ev, kAmountEditID) );
  122.         fCalcPart->MySetAnnualInterestPercent( MyGetEditValue(ev, kInterestEditID) );
  123.         fCalcPart->MySetLoanYears( MyGetEditValue(ev, kYearsEditID) );
  124.  
  125.         double payment = fCalcPart->MyComputePayment(ev);
  126.         MySetEditValue(ev, kAnswerEditID, payment);
  127.     }
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. double 
  132. CCalcFrame::MyGetEditValue(Environment* ev, ODID viewID)
  133. {
  134.     FW_CEditView* view = (FW_CEditView*)FindViewById(ev, viewID);
  135.     FW_CString valueStr = view->GetText(ev);
  136.     double value = valueStr.ParseAsRealNumber();
  137.     return (double)value;
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. void 
  142. CCalcFrame::MySetEditValue(Environment* ev, ODID viewID, double value, short fracDigits)
  143. {
  144.     FW_CString32 valueStr;
  145.     valueStr.ReplaceAllAsRealNumber(value, fracDigits);
  146.     FW_CEditView* view = (FW_CEditView*)FindViewById(ev, viewID);
  147.     view->SetText(ev, valueStr);
  148. //    view->Invalidate(ev);
  149. }
  150.